package com.cskaoyan.market.db.common;

import java.util.List;

import com.github.pagehelper.PageInfo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 小焦
 * @since 2023/03/18 20:58
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CommonData<T> {

    /**
     * total : 3 pages : 1 limit : 3 page : 1 list :
     * [{"value":1,"label":"超级管理员"},{"value":2,"label":"商场管理员"},{"value":3,"label":"推广管理员"}]
     */

    private Integer total;
    private Integer pages;
    private Integer limit;
    private Integer page;
    private List<T> list;

    public static <T> CommonData<T> data(PageInfo<T> pageInfo) {
        int pages = pageInfo.getPages();
        int pageNum = pageInfo.getPageNum();
        int pageSize = pageInfo.getPageSize();
        int total = (int)pageInfo.getTotal();
        List<T> list = pageInfo.getList();
        return new CommonData<T>(total, pages, pageSize, pageNum, list);
    }

    public static <T> CommonData<T> dataWithList(List<T> objectList) {
        int pages = 1;
        int pageNum = 1;
        int pageSize = objectList.size();
        int total = objectList.size();
        List<T> list = objectList;
        return new CommonData<T>(total, pages, pageSize, pageNum, list);
    }

}
